/*
 * AS_FINDUSER.cpp
 *
 *  Created on: 2014. 3. 20.
 *      Author: zenoniaonline
 */


#include "../../User.h"
#include "../../Proxy.h"
#include "../../Command.h"
#include "../../NLogic/Space.h"
#include "../../NLogic/Battle.h"

namespace ProjectZ { namespace NCommand {

void Command::AS_FINDUSER(User * pUser, ::Network::Packet * pPacket)
{
	PREPARE_PACKET;

	int32_t userSeq = 0;
	* pPacket >> userSeq;

	User * pKickUser = NProxy::GetUser(userSeq);
	if (NULL == pKickUser)
	{
		::Network::Packet * pAck = ::Network::GETPACKETPOOL()->SEND_NEW();
		*pAck << static_cast<int16_t>(ACK_UNKNOWN_ERROR) << static_cast<int32_t>(userSeq) << static_cast<int32_t>(0);
		pAck->MakePacket(CMD_SA_FINDUSER);
		pUser->Send(pAck);
		return;
	}

	//if (2 <= pKickUser->GetRefCount())
	{
		::Logger::GETLOG()->ToAll(::Logger::OBSERVER, "FINDUSER> RefCount=%d, GID : %d", pKickUser->GetRefCount(), pKickUser->GetUserSeq());
		pKickUser->RewindState();
		pKickUser->RewindEnumState();
	}

	//DEBUGLOG("%s userSeq : %d UserState : %s enumstate : %d GID : %d", __FUNCTION__, userSeq, pKickUser->GetState()->GetName().c_str(), pKickUser->GetEnumState(), pKickUser->GetUserSeq());

	::Network::Packet * pAck = ::Network::GETPACKETPOOL()->SEND_NEW();
	* pAck << static_cast<int16_t>(ACK_OK) << static_cast<int32_t>(userSeq) << static_cast<int32_t>(pKickUser->GetUserSeq());
	* pAck << static_cast<int16_t>(pKickUser->GetRefCount());
	* pAck << pKickUser->GetState()->GetName().c_str();
	* pAck << static_cast<int16_t>(pKickUser->GetEnumState());
	pAck->MakePacket(CMD_SA_FINDUSER);
	pUser->Send(pAck);

}

} /*NCommand*/ } /*ProjectZ*/

